Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix promoted properties sharing context #1619

Merged

Conversation

rasmuscnielsen
Copy link
Contributor

A reproduction of the bug described in my comment here: #1419 (comment)

Added regression test + fixed it with a clone of context. Tests passing. However - suggestions for alternative fixes are very welcome.

Copy link
Collaborator

@DerManoMann DerManoMann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small change, but otherwise I suppose this is ok.

@@ -80,6 +80,9 @@ public function build(\Reflector $reflector, Context $context): array
$instance->nullable = $nullable ?: Generator::UNDEFINED;

if ($rp->isPromoted()) {
// ensure each property has its own context
$instance->_context = clone $instance->_context;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not so keen on clone - could we use this instead?

Suggested change
$instance->_context = clone $instance->_context;
$instance->_context = new Context([], $instance->_context);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed :-)

@rasmuscnielsen rasmuscnielsen force-pushed the fix/promoted-properties-context branch from 7024838 to 1645bd0 Compare July 3, 2024 07:06
@DerManoMann DerManoMann merged commit 4756339 into zircote:master Jul 3, 2024
21 checks passed
@DerManoMann
Copy link
Collaborator

Thanks @rasmuscnielsen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants